<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    <style>
        .mint-tab-container-wrap {
            display: -webkit-box;
            display: -ms-flexbox;
            display: flex;
            height: 100% !important;
        }

        .mint-tab-item.is-selected {
            border-left: 3px solid #26a2ff !important;
            border-bottom: 0px !important;
            color: #26a2ff;
            margin-bottom: -3px;
            background: white;
        }

        .mint-tab-item {
            display: block;
            -webkit-box-flex: 1;
            -ms-flex: 1;
            flex: 0 !important;
            height: 55px !important;
            width: 90px !important;
            text-decoration: none;
            background: #E9F3FF;
        }

        .mint-tab-item-label {
            color: inherit;
            font-size: 15px !important;
            line-height: 1;
        }
    </style>
    <script>
        document.getElementsByTagName('html')[0].style.fontSize = '15px'
    </script>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="./css/common.css">
    <link rel="stylesheet" href="./css/icon.css">
    <link rel="stylesheet" href="./css/mint.min.css">
    <!-- 先引入 Vue -->
    <script src="js/vue.min.js"></script>
    <!-- 引入组件库 -->
    <script src="js/mint.min.js"></script>
    <!--web请求-->
    <script src="js/webservice.js"></script>
    <title>医嘱单</title>
</head>
<body>
<div class="bgwhite matchH" id="app">
    <div class="flexH fixedScroll">
        <mt-navbar class="flexVL fixedScroll" v-model="selected">
            <template v-for="(itm,idx)  in patInfoList">
                <mt-tab-item :id="idx">
                    <div v-cloak class="flexH">{{itm.bedCode + "  " + itm.name}}</div>
                </mt-tab-item>
            </template>
        </mt-navbar>
        <div class="flexG flexVL fixedScroll marginL100 bgwhite">
            <div class="fixed bgwhite">
                <div v-cloak class="flexHL  margin10 ">优先级
                    <div class="flexHL" v-for="(itm,idx) in ordPriority">
                        <div v-cloak @click="onPriorityClick(idx)" :class="getStyleClass(idx,priorityIndex)">{{itm.desc }}</div>
                    </div>
                </div>
                <div v-cloak class="flexHL  margin10 ">状 态
                    <div class="flexHL" v-for="(itm,idx) in ordStatus">
                        <div v-cloak @click="onStatusClick(idx)" :class="getStyleClass(idx,statusIndex)">{{itm.desc }}</div>
                    </div>
                </div>
                <div v-cloak class="flexHL margin10 ">类 别
                    <div class="flexHL" v-for="(itm,idx) in ordType">
                        <div v-cloak @click="onTypeClick(idx)" :class="getStyleClass(idx,typeIndex)">{{itm.desc }}</div>
                    </div>
                </div>
                <div id="msg"></div>
            </div>

            <div class="flexVL marginT150">
                <div v-for="(item,indx) in ordList" v-if="getHideShow(item)" class="flexVL marginT5"
                     :key="item[0].orderId">
                    <div class="flexHL">
                        <div class="font12 width40 marginT5 radius20 center" :style="getStaColor(item[0].ordPriority)">
                            {{item[0].ordPriority}}
                        </div>
                        <div v-if="item[0].ordStatus=='停止'" class="font12 width40 marginT5 radius20 center marginL10"
                             style="background: #AAAAAA; color:white">
                            {{item[0].ordStatus}}
                        </div>
                        <div v-if="item[0].filteFlagExtend=='JP'"
                             class="font12 width40 marginT5 radius20 center marginL10"
                             style="background: #4C95EF; color:white">
                            静配
                        </div>
                    </div>

                    <div v-for="(cItem,cIndx) in item">
                        <div class="font17 fontBold marginT5">{{cItem.orddesc}}</div>
                        <div v-if="cItem.orddose" class="font14 gray marginT5">{{cItem.orddose}}</div>
                    </div>
                    <div class="font14 gray marginT5">
                        {{item[0].ordstarttime + "  " + item[0].ctcpDesc + "  " + item[0].phcinDesc + "  " + item[0].phcfrCode}}
                    </div>
                    <div class="font14 gray marginT5">{{item[0].ordstoptime + " " + item[0].stopDoctor}}</div>
                    <div class="line marginTB5"></div>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script>
    var tag = ""
    var tUserId = "1885";
    var tLocId = "8";
    var tWardId = "3";
    var tGroupId = "";
    var tHospitalId = "";

    function getString(s) {
        if (tag == "USERID") {
            tUserId = s;
            getSPString("LOCID") //第2个调用
        } else if (tag == "LOCID") {
            tLocId = s;
            getSPString("WARDID") //第3个调用
        } else if (tag == "WARDID") {
            tWardId = s;
        }
    }

    function getSPString(key) {
        if (window.android) {
            tag = key;
            window.android.callAndroid("com.blankj.utilcode.util.SPStaticUtils:getString(" + key + ")", "call");
        }
    }

    //添加鸿蒙 传递用户信息
    window.addEventListener('message', function (event) {
        if (event.data === 'init_web_messageport') {
            //document.getElementById("msg").innerHTML = event.data+""
            if (event.ports[0] != null) {
                h5Port = event.ports[0]; // 1. 保存从ets侧发送过来的端口
                h5Port.onmessage = function (event) {
                    var result = event.data;// 2. 接收ets侧发送过来的消息.
                    console.log("In html got message, result: ", (result));
                    if (typeof (result) == "string") {
                        //固定格式：hospitalId,groupId,wardId,userId,locId
                        var arr = result.split(",");
                        tHospitalId = arr[0];
                        tGroupId = arr[1];
                        tWardId = arr[2];
                        tUserId = arr[3];
                        tLocId = arr[4];
                        var txt = tHospitalId + "-" + tGroupId + "-" + tWardId + "-" + tUserId + "-" + tLocId
                        //document.getElementById("msg").innerHTML = txt
                        initVue();
                    }
                }
            }
        }
    })
    //第1个调用
    getSPString("USERID")
    //Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36 Edg/128.0.0.0
    var ua = navigator.userAgent
    if (ua.includes("OpenHarmony") || ua.includes("Linux")) {
        //鸿蒙不处理
    } else if (ua.includes("Windows") ) {
        initVue() //浏览器 直接打开
    }
    //document.getElementById("msg").innerHTML = "String:" + navigator.userAgent

    function initVue() {
        new Vue({
            el: '#app',
            data: {
                selected: 0,
                priorityIndex: 0,
                statusIndex: 0,
                typeIndex: 0,
                priorityClass: "",
                patInfoList: [],
                ordPriority: [],
                ordStatus: [],
                ordType: [],
                ordList: [],
                hideShow: true,
                priority: "",
                status: "",
                type: "",
            },
            watch: {
                selected(val) {
                    console.log(val)
                    this.episodeId = this.patInfoList[val].episodeId
                    this.getOrderList(this.episodeId)
                }
            },
            mounted() {
                //将要给原生调用的方法挂载到 window 上面
                window.Config = this.Config
                window.getScanMsg = this.getScanMsg
                window.GetInWardPatList = this.GetInWardPatList
                window.GetDocOrderList = this.GetDocOrderList
                this.initData()
            },
            methods: {
                //获取扫码
                getScanMsg(scanInfo) {
                    this.$toast(scanInfo)
                },
                GetInWardPatList(data) {
                    this.patInfoList = data.patInfoList
                    if (this.patInfoList.length > 0) { //加载第一个患者
                        this.getOrderList(this.patInfoList[0].episodeId)
                    }
                },
                GetDocOrderList(data) {
                    Http.hideLoading(this)
                    this.ordList = data.ordList
                    this.ordPriority = data.ordPriority
                    this.ordStatus = data.ordStatus
                    this.ordType = data.ordType
                },
                getOrderList(episodeId) {
                    console.log(episodeId)
                    this.priorityIndex = 0;
                    this.statusIndex = 0;
                    this.typeIndex = 0;
                    this.priority = ""
                    this.status = ""
                    this.type = ""
                    this.ordList = []
                    var params = {
                        wardId: tWardId,
                        episodId: episodeId,
                    }
                    Http.postPlus("GetDocOrderList", params, (data) => {
                        console.log(data)
                        this.GetDocOrderList(data);
                    })
                },
                initData() {
                    var params = {
                        wardId: tWardId,
                        userId: tUserId,
                        module: "Ward",
                    }
                    Http.showLoading(this)
                    Http.postPlus("GetInWardPatList", params, (data) => {
                        console.log(data)
                        this.GetInWardPatList(data);
                    })
                },
                getStaColor(sta) {
                    if (sta === "长期") {
                        return 'background: red; color:white'
                    }
                    return 'background: #B8DA64; color:white'
                },
                onPriorityClick(index) {
                    this.priorityIndex = index;
                    this.refreshDatas();
                },
                getStyleClass(index, idx) {
                    if (index === idx) {
                        return "bgblue colorwhite padding5 marginL10 radius5 font12";
                    }
                    return "bggrayf7 colorblack padding5 marginL10 radius5 font12";
                },
                onStatusClick(index) {
                    this.statusIndex = index;
                    this.refreshDatas();
                },
                onTypeClick(index) {
                    this.typeIndex = index;
                    this.refreshDatas();
                },
                refreshDatas() {
                    this.priority = this.ordPriority[this.priorityIndex].desc
                    if (this.priority === "全部") this.priority = ""
                    this.status = this.ordStatus[this.statusIndex].desc
                    if (this.status === "全部") this.status = ""
                    this.type = this.ordType[this.typeIndex].desc
                    if (this.type === "全部") this.type = ""
                    console.log(this.priority + " " + this.status + " " + this.type)
                },
                getHideShow(itm) {
                    var ordPriority = itm[0].ordPriority
                    var ordStatus = itm[0].ordStatus
                    var ordType = itm[0].ordType
                    if (this.priority !== "" && ordPriority !== this.priority) {
                        return false
                    } else if (this.status !== "" && ordStatus !== this.status) {
                        return false
                    } else if (this.type !== "" && ordType !== this.type) {
                        return false
                    }
                    return true
                }
            }
        })
    }

</script>

</html>